<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    #div1{
        height: 20px;
        width: 20px;
        background-color: yellowgreen;
        border: solid 1px gray;
        position: absolute;
        left: 0px;
        top: 100px;
    }
</style>
<script>
    window.onload = function() {
        var btn = document.getElementById("btn1");
        var div1 = document.getElementById("div1");
        var speed = 7;
        var timer;

        btn.onclick = function(){
            clearInterval(timer)
            timer = setInterval(function() {
                console.log(div1.offsetLeft)
                if (div1.offsetLeft >= 500) {
                    clearInterval(timer);
                } else {
                    div1.style.left = div1.offsetLeft + speed + 'px';
                }
            }, 30);
        };
    }
</script>
<body>
    <div id="div1">
        <ul>
            
        </ul>
    </div>
</body>
</html>